﻿#region Using

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraTab;
using System.Data;
using DevExpress.XtraTreeList;
using System.Data.SqlClient;
#endregion Using

namespace TCCT_CTC_CSDLDangVienV1
{
    public partial class frmBase : DevExpress.XtraEditors.XtraForm
    {
        public frmBase()
        {
            InitializeComponent();
        }




        #region Properties
        #region ValidationMessage

        public ArrayList _validationRequire = null;

        public ArrayList ValidationRequire
        {
            get
            {
                if (_validationRequire == null)
                    _validationRequire = new ArrayList();
                return _validationRequire;
            }
            set
            {
                _validationRequire = value;
            }
        }

        public ArrayList _validationMessage = null;

        /// <summary>
        /// Lưu toàn bộ validation message để hiển thị đồng thời
        /// </summary>
        /// <value>The validation message.</value>
        public ArrayList ValidationMessage
        {
            get
            {
                if (_validationMessage == null)
                {
                    _validationMessage = new ArrayList();
                }
                return _validationMessage;
            }
            set
            {
                _validationMessage = value;
            }
        }

        #endregion ValidationMessage

        #endregion Properties

        #region Static Methods

        #region AppendTable

        /// <summary>
        /// Appends the table.
        /// Sodv: Nối 2 bảng dữ liệu có cùng một cấu trúc
        /// Bảng dích (taget) phải có cột được sét Unique
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="taget">The taget.</param>
        public static void AppendTable(DataTable source, DataTable taget)
        {
            try
            {
                foreach (DataRow sRow in source.Rows)
                {
                    DataRow addRow = taget.NewRow();
                    for (int i = 0; i < source.Columns.Count; i++)
                    {
                        addRow[i] = sRow[i];
                    }
                    //Phải sử dụng Try - catch vì dòng add vào có thể đã tồn tại trong source (Unique)
                    try
                    {
                        taget.Rows.Add(addRow);
                    }
                    catch { }
                }
                taget.AcceptChanges();
            }
            catch { }
        }

        #endregion AppendTable

        #region GetProperty

        public static string GetProperty(object container, string property)
        {
            return GetProperty(container, property, string.Empty);
        }

        public static string GetProperty(object container, string property, string defaut)
        {
            return GetProperty(container, property, defaut, ""); // TODO: SonP REM ApplicationContext.Current.CurrentLanguage);
        }

        public static string GetProperty(object container, string property, string defaut, string lang)
        {
            try
            {
                string result;
                string fieldname = property;

                if (lang.Length > 0 && fieldname.IndexOf("_" + lang) < -1)
                    fieldname = fieldname + "_" + lang;

                if (container is DataRowView)
                {
                    try
                    {
                        result = ((DataRowView)container)[fieldname].ToString();
                    }
                    catch
                    {
                        result = ((DataRowView)container)[property].ToString();
                    }
                }
                else if (container is DataRow)
                {
                    try
                    {
                        result = ((DataRow)container)[fieldname].ToString();
                    }
                    catch
                    {
                        result = ((DataRow)container)[property].ToString();
                    }
                }
                else if (container is IDictionary)
                {
                    try
                    {
                        result = ((IDictionary)container)[fieldname].ToString();
                    }
                    catch
                    {
                        result = ((IDictionary)container)[property].ToString();
                    }
                }
                else if (container is string)
                {
                    result = container.ToString();
                }
                else
                {
                    result = defaut;
                }
                if (result.Length == 0)
                    return defaut;
                else
                    return result;
            }
            catch // Is null
            {
                return defaut;
            }
        }

        #endregion GetProperty

        #region GetValue

        //public static object GetGridValue(


        #region GetDouble

        #region Object

        public static double GetDouble(object obj, double defaultValue)
        {
            try
            {
                return Convert.ToDouble(obj);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion Object

        #region Label

        public static double GetDouble(LabelControl control)
        {
            try
            {
                return Convert.ToDouble(control.Text.Trim());
            }
            catch
            {
                return double.MinValue;
            }
        }

        #endregion Label

        #region TextEdit

        public static double GetDouble(TextEdit text)
        {
            try
            {
                return Convert.ToDouble(text.EditValue);
            }
            catch
            {
                return 0;
            }
        }

        #endregion TextEdit

        #region String

        public static double GetDouble(string str, double defaultValue)
        {
            try
            {
                return Convert.ToDouble(str);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion GetDouble

        #region RadioGroupEditControl

        public static double GetDouble(RadioGroup control, double defaultValue)
        {
            try
            {
                return Convert.ToDouble(control.EditValue);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion RadioGroupEditControl

        #region TextEditControl

        public static double GetDouble(TextEdit control, double defaultValue)
        {
            try
            {
                return Convert.ToDouble(control.Text.Trim());
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion TextEditControl

        #region ComboboxEditControl

        public static double GetDouble(ComboBoxEdit control, double defaultValue)
        {
            try
            {
                return Convert.ToDouble(control.EditValue);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion ComboboxEditControl

        #region ListBoxControl



        #endregion ListBoxControl

        #region LookUpEditControl

        public static double LookUpEditControl(LookUpEdit control, double defaultValue)
        {
            try
            {
                return Convert.ToDouble(control.EditValue);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion LookUpEditControl

        #region GridControl

        public double GetDouble(GridControl control, int rowIndex, int colIndex)
        {
            try
            {
                DevExpress.XtraGrid.Views.Grid.GridView curView = (DevExpress.XtraGrid.Views.Grid.GridView)control.MainView;
                object objValue = curView.GetRowCellValue(rowIndex, curView.Columns[colIndex]);
                return Convert.ToDouble(objValue);
            }
            catch
            {
                return double.MinValue;
            }
        }

        public static double GetDouble(GridControl control, int rowIndex, string colName)
        {
            try
            {
                GridView curView = (GridView)control.MainView;
                object objValue = curView.GetRowCellValue(rowIndex, colName);
                return Convert.ToDouble(objValue);
            }
            catch
            {
                return 0;
            }
        }

        #endregion GridControl

        #endregion GetDouble

        #region GetDateTime

        #region Object

        public static System.DateTime GetDateTime(object obj, System.DateTime defaultValue)
        {
            try
            {
                return Convert.ToDateTime(obj);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion GetDouble

        #region String

        public static System.DateTime GetLong(string str, System.DateTime defaultValue)
        {
            try
            {
                return Convert.ToDateTime(str);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion String

        #region DateEdit
        /// <summary>
        /// Get date and time value of control
        /// Return defaultValue if error occurs
        /// </summary>
        /// <param name="control"></param>
        /// <param name="defaultValue">Default return value</param>
        /// <returns>Return DateTime</returns>
        public static DateTime GetDateTime(DateEdit control, DateTime defaultValue)
        {
            try
            {
                DateTime dtRet;
                dtRet = DateTime.ParseExact(control.Text, control.Properties.DisplayFormat.FormatString, null);
                //dtRet = Convert.ToDateTime(control.EditValue).Date;
                return dtRet;
            }
            catch
            {
                return defaultValue;
            }
        }

        /// <summary>
        /// Gets the date time.
        /// On error return minValue of Datetime
        /// </summary>
        /// <param name="control">The control.</param>
        /// <returns></returns>
        public static DateTime GetDateTime(DateEdit control)
        {
            return GetDateTime(control, DateTime.MinValue);
        }

        /// <summary>
        /// Gets the date.
        /// On error return minValue of Date 
        /// </summary>
        /// <param name="control">The control.</param>
        /// <returns></returns>
        public static DateTime GetDate(DateEdit control)
        {
            return GetDateTime(control).Date;
        }
        /// <summary>
        /// Hàm trả về giá trị date từ chuỗi dạng ngày tháng việt nam
        /// </summary>
        /// <param name="control"></param>
        /// <returns></returns>
        public static Nullable<DateTime> GetDate(TextEdit control)
        {
            try
            {
                if (IsNull(control))
                    return null;

                string[] arrD = control.Text.Trim().Split('/');

                return new DateTime(Util.ToInt(arrD[2]), Util.ToInt(arrD[1]), Util.ToInt(arrD[0])).Date;

            }
            catch
            {
                return null;
            }
        }

        #endregion DateEdit


        #endregion GetDateTime

        #region GetLong

        #region Object

        public static long GetLong(object obj, long defaultValue)
        {
            try
            {
                return Convert.ToInt64(obj);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion Object

        #region String

        public static long GetLong(string str, long defaultValue)
        {
            try
            {
                return Convert.ToInt64(str);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion String

        #region RadioGroupEditControl

        public static long GetLong(RadioGroup control, long defaultValue)
        {
            try
            {
                return Convert.ToInt64(control.EditValue);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion RadioGroupEditControl

        #region SetEnable
        #endregion

        #region SetReadonly
        #endregion

        #region SetVisible
        public static void SetVisible(BarButtonItem btn, string ChucNangCode)
        {
            //   btn.vi = Security.Instance.HasRight(ChucNangCode);

        }

        public static void SetVisible(Control control, string ChucNangCode)
        {
            //control.Visible=Security.Instance

        }
        //public static void SetVisible(d btn,string ChucNangCode)
        //{
        //    btn.

        //}
        #endregion


        #region TextEditControl

        public static long GetLong(TextEdit control, long defaultValue)
        {
            try
            {
                return Convert.ToInt64(control.Text.Trim());
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion TextEditControl

        #region ComboboxEdit

        public static long GetLong(ComboBoxEdit control, long defaultValue)
        {
            try
            {
                return Convert.ToInt64(control.EditValue);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion ComboboxEdit

        #region LookUpEdit

        /// <summary>
        /// Gets the long.
        /// On error return 0
        /// </summary>
        /// <param name="control">The control.</param>
        /// <returns></returns>
        public static long GetLong(LookUpEdit control)
        {
            try
            {
                return Convert.ToInt64(control.EditValue);
            }
            catch
            {
                return 0;
            }
        }
        public static Nullable<long> GetLongNull(LookUpEdit control)
        {
            try
            {
                return long.Parse(control.EditValue.ToString());
            }
            catch
            {
                return null;
            }
        }

        public static long GetLong(GridLookUpEdit control)
        {
            try
            {
                return Convert.ToInt64(control.EditValue);
            }
            catch
            {
                return 0;
            }
        }

        public static long GetLong(LookUpEdit control, long defaultValue)
        {
            try
            {
                if (IsNull(control))
                    return defaultValue;
                return Convert.ToInt64(control.EditValue);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion LookUpEdit

        #region ButtonEdit
        /// <summary>
        /// Gets the long.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <returns></returns>
        public static long GetLong(ButtonEdit control, long defaultValue)
        {
            try
            {
                if (IsNull(control))
                    return defaultValue;
                return Convert.ToInt64(control.EditValue);
            }
            catch
            {
                return defaultValue;
            }
        }
        /// <summary>
        /// Gets the long.
        /// On error return long.MinValue
        /// </summary>
        /// <param name="control">The control.</param>
        /// <returns></returns>
        public static long GetLong(ButtonEdit control)
        {
            try
            {
                if (IsNull(control))
                    return long.MinValue;
                return Convert.ToInt64(control.EditValue);
            }
            catch
            {
                return long.MinValue;
            }
        }
        #endregion ButtonEdit

        #region GridView

        public static long GetLong(GridControl control, int rowIndex, int colIndex, long defaultValue)
        {
            try
            {
                DevExpress.XtraGrid.Views.Grid.GridView curView = (DevExpress.XtraGrid.Views.Grid.GridView)control.MainView;
                object objValue = curView.GetRowCellValue(rowIndex, curView.Columns[colIndex]);
                return Convert.ToInt64(objValue);
            }
            catch
            {
                return defaultValue;
            }
        }

        public static long GetLong(GridControl control, int rowIndex, int colIndex)
        {
            return GetLong(control, rowIndex, colIndex, 0);
        }

        public static long GetLong(GridControl control, int rowIndex, string colName, long defaultValue)
        {
            try
            {
                DevExpress.XtraGrid.Views.Grid.GridView curView = (DevExpress.XtraGrid.Views.Grid.GridView)control.MainView;
                object objValue = curView.GetRowCellValue(rowIndex, colName);
                return Convert.ToInt64(objValue);
            }
            catch
            {
                return defaultValue;
            }
        }

        public static long GetLong(GridControl control, int rowIndex, string colName)
        {
            return GetLong(control, rowIndex, colName, 0);
        }

        #endregion GridView

        #region TextEdit

        public static long GetLong(TextEdit control)
        {
            try
            {
                return Convert.ToInt64(control.Text.Trim().Replace(",", ""));
            }
            catch
            {
                return 0;
            }
        }

        #endregion TextEdit

        #region ListBoxControl



        #endregion ListBoxControl



        #endregion GetLong

        #region GetBool

        #region CheckEdit

        public static bool GetBool(CheckEdit checkEdit, bool defaultValue)
        {
            try
            {
                if (checkEdit.Checked)
                    return true;
                else
                    return false;
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion CheckEdit

        #region Object

        public static bool GetBool(object obj, bool defaultValue)
        {
            try
            {
                return Convert.ToBoolean(obj);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion GetDouble

        #region String

        public static bool GetBool(string str, bool defaultValue)
        {
            try
            {
                return Convert.ToBoolean(str);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion String

        #endregion GetBool

        #region GetInterger

        #region Object

        public static Int32 GetInterger(object obj, int defaultValue)
        {
            try
            {
                return Convert.ToInt32(obj);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion Object

        #region String

        public static Int32 GetInterger(string str, int defaultValue)
        {
            try
            {
                return Convert.ToInt32(str);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion String

        #region RadioGroupEditControl

        public static Int32 GetInterger(RadioGroup control, int defaultValue)
        {
            try
            {
                return Convert.ToInt32(control.EditValue);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion RadioGroupEditControl

        #region TextEditControl

        public static Int32 GetInterger(TextEdit control, int defaultValue)
        {
            try
            {
                return Convert.ToInt32(control.Text.Trim());
            }
            catch
            {
                return defaultValue;
            }
        }

        /// <summary>
        /// Gets the int.
        /// On error return 0
        /// </summary>
        /// <param name="control">The control. </param>
        /// <returns></returns>
        public static Int32 GetInterger(TextEdit control)
        {
            try
            {
                return Convert.ToInt32(control.EditValue);
            }
            catch
            {
                return 0;
            }
        }

        #endregion TextEditControl

        #region ComboboxEdit

       
        #endregion ComboboxEdit

        #region LookUpEdit

        public static Int32 GetInterger(LookUpEdit control, int defaultValue)
        {
            try
            {
                return Convert.ToInt32(control.EditValue);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion ComboboxEdit

        #region ListBoxControl



        #endregion ListBoxControl

        #region LookUpEditControl

        public static Int32 LookUpEditControl(LookUpEdit control, Int32 defaultValue)
        {
            try
            {
                return Convert.ToInt32(control.EditValue);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion LookUpEditControl

        #endregion GetInterger

        #region GetString

        #region Object

        public static string GetString(object obj, string defaultValue)
        {
            try
            {
                return Convert.ToString(obj);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion Object

        #region RadioGroupEditControl

        public static string GetString(RadioGroup control, string defaultValue)
        {
            try
            {
                return Convert.ToString(control.EditValue);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion RadioGroupEditControl

        #region TextEditControl

        public static string GetString(TextEdit control, string defaultValue)
        {
            try
            {
                if (IsNull(control))
                    return defaultValue;

                return Convert.ToString(control.Text.Trim());
            }
            catch
            {
                return defaultValue;
            }
        }

        /// <summary>
        /// Gets the string.
        /// On error return string.Empty
        /// </summary>
        /// <param name="control">The control.</param>
        /// <returns></returns>
        public static string GetString(TextEdit control)
        {
            try
            {
                if (IsNull(control))
                    return string.Empty;

                return Convert.ToString(control.Text.Trim());
            }
            catch
            {
                return string.Empty;
            }
        }

        public static string GetString(MemoEdit control)
        {
            try
            {
                if (IsNull(control))
                    return string.Empty;

                return Convert.ToString(control.EditValue).Trim();
            }
            catch
            {
                return string.Empty;
            }
        }

        #endregion TextEditControl

        #region ComboboxEdit

        public static string GetString(ComboBoxEdit control, string defaultValue)
        {
            try
            {
                if (IsNull(control))
                    return string.Empty;

                return Convert.ToString(control.EditValue);
            }
            catch
            {
                return defaultValue;
            }
        }
        public static string GetString(ComboBoxEdit control)
        {
            try
            {
                if (IsNull(control))
                    return string.Empty;

                return Convert.ToString(control.EditValue);
            }
            catch
            {
                return "";
            }
        }

        #endregion ComboboxEdit

        #region LookUpEdit

        /// <summary>
        /// Gets the string.
        /// Return string.Empty when error
        /// </summary>
        /// <param name="control">The control.</param>
        /// <returns></returns>
        public static string GetString(LookUpEdit control)
        {
            return GetString(control, string.Empty);
        }

        public static string GetString(LookUpEdit control, string defaultValue)
        {
            try
            {
                if (IsNull(control))
                    return defaultValue;

                return Convert.ToString(control.EditValue);
            }
            catch
            {
                return string.Empty;
            }
        }

        #endregion LookUpEdit


        #region ListBoxControl



        #endregion ListBoxControl


        #region ButtonEdit

        /// <summary>
        /// Gets the string.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <returns></returns>
        public static string GetString(ButtonEdit control, string defaultValue)
        {
            try
            {
                if (IsNull(control))
                    return defaultValue;

                return Convert.ToString(control.Text.Trim());
            }
            catch
            {
                return defaultValue;
            }
        }

        /// <summary>
        /// Gets the string.
        /// On error return string.Empty
        /// </summary>
        /// <param name="control">The control.</param>
        /// <returns></returns>
        public static string GetString(ButtonEdit control)
        {
            try
            {
                if (IsNull(control))
                    return string.Empty;

                return Convert.ToString(control.Text.Trim());
            }
            catch
            {
                return string.Empty;
            }
        }

        #endregion ButtonEdit

        #region Treeview

        public static string GetString(DevExpress.XtraTreeList.TreeList control, string fieldName)
        {
            return control.FocusedNode.GetValue(fieldName).ToString();
        }
        #endregion Treeview
        #region GridControl

        public static string GetString(GridControl control, string fieldName)
        {
            return UI.Grid.GetGridValueString(control, fieldName);
        }

        public static string GetString(GridControl control, int rowIndex, int colIndex)
        {
            try
            {
                DevExpress.XtraGrid.Views.Grid.GridView curView = (DevExpress.XtraGrid.Views.Grid.GridView)control.MainView;
                object objValue = curView.GetRowCellValue(rowIndex, curView.Columns[colIndex]);
                return Convert.ToString(objValue);
            }
            catch
            {
                return string.Empty;
            }
        }

        public static string GetString(GridControl control, int rowIndex, string colName)
        {
            try
            {
                DevExpress.XtraGrid.Views.Grid.GridView curView = (DevExpress.XtraGrid.Views.Grid.GridView)control.MainView;
                object objValue = curView.GetRowCellValue(rowIndex, colName);
                return Convert.ToString(objValue);
            }
            catch
            {
                return string.Empty;
            }
        }


        public static double GetDouble(GridControl control, string fieldName)
        {
            try
            {
                return UI.Grid.GetGridValueDouble(control, fieldName);
            }
            catch
            {
                return 0;
            }
        }
        public static int GetInt(GridControl control, string fieldName)
        {
            try
            {
                return UI.Grid.GetGridValueInt(control, fieldName);
            }
            catch
            {
                return 0;
            }
        }

        #endregion GridControl

        #endregion GetString

        #region GetGuid

        public static Guid ToGuid(object value, Guid defaultValue)
        {
            try
            {
                return new Guid(value.ToString());
            }
            catch
            {
                return defaultValue;
            }
        }

        public static Guid ToGuid(object value)
        {
            return ToGuid(value, Guid.Empty);
        }

        #endregion GetGuid

        #endregion GetValue

        #region SetValue

        #region TextEditControl

        public static void SetValue(TextEdit control, string value)
        {
            if (control == null)
                return;
            control.Text = value;
        }

        public static void SetValue(TextEdit control, double value)
        {
            if (control == null)
                return;
            control.EditValue = value;
        }
        public static void SetValue(TextEdit control, object value)
        {
            if (control == null)
                return;
            control.EditValue = value;
        }
        #endregion TextEditControl

        #region MomoEditControl

        public static void SetValue(MemoEdit control, string value)
        {
            if (control == null)
                return;
            control.EditValue = value;
        }

        #endregion MomoEditControl

        #region TextBoxControl

        public static void SetValue(TextBox control, string value)
        {
            if (control == null)
                return;
            control.Text = value;
        }

        #endregion TextControl

        #region CheckEdit

        public static void SetValue(CheckEdit control, bool value)
        {
            if (control == null)
                return;
            control.Checked = value;
        }

        #endregion CheckEdit

        #region DateEdit

        public static void SetValue(DateEdit control, DateTime value)
        {
            if (control == null)
                return;
            control.EditValue = value;
            if (value == DateTime.MinValue)
                control.Text = string.Empty;
        }

        #endregion DateEdit

        #region HyperLinkEdit

        public static void SetValue(HyperLinkEdit control, string value)
        {
            if (control == null)
                return;
            control.Text = value;
        }

        #endregion HyperLinkEdit

        #region ImageEdit

        public static void SetValue(ImageEdit control, string value)
        {
            if (control == null)
                return;
            //ontrol.Properties.i
        }

        #endregion ImageEdit

        #region LabelControl

        public static void SetValue(LabelControl control, string value)
        {
            if (control == null)
                return;
            control.Text = value;
        }

        #endregion LabelControl

        #region LookUpEditControl

        public static void SetValue(LookUpEdit control, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                control.ItemIndex = -1;
                control.EditValue = null;
                return;
            }

            SetValueLookUp(control, value);
        }

        public static void SetValue(LookUpEdit control, long value)
        {
            if (value == 0)
            {
                control.ItemIndex = 0;
                return;
            }

            SetValueLookUp(control, value);
        }
        public static void SetValue(GridLookUpEdit control, long value)
        {
            if (value <= 0)
            {
                control.EditValue = null;
                return;
            }
            control.EditValue = value;

        }
        public static void SetValueLookUp(LookUpEdit control, object value)
        {
            bool currentRO = control.Properties.ReadOnly;

            control.Properties.ReadOnly = false;
            int itemIndex = control.Properties.GetDataSourceRowIndex(
                control.Properties.ValueMember, value);
            control.ItemIndex = itemIndex;
            control.Properties.ReadOnly = currentRO;
        }

        #endregion LookUpEditControl

        #region ButtonEdit

        public static void SetValue(ButtonEdit control, string value)
        {
            if (control == null)
                return;
            control.Text = value;
        }


        #endregion ButtonEdit


        #endregion SetValue

        #region IsNull

        public static bool IsNull(TextEdit control)
        {
            return control.Text.Trim().Length == 0;
        }

        public static bool IsNull(MemoEdit control)
        {
            return control.Text.Trim().Length == 0;
        }

        public static bool IsNull(LookUpEdit control)
        {
            return control.ItemIndex == -1 || control.EditValue == DBNull.Value || control.EditValue == null;
        }

        public static bool IsNull(GridLookUpEdit control)
        {
            return control.EditValue == null || control.EditValue == DBNull.Value || control.EditValue.ToString().Length == 0;
        }

        public static bool IsNull(ButtonEdit control)
        {
            return control.Text.Trim().Length == 0;
        }
        public static bool IsNull(ComboBoxEdit control)
        {
            return control.EditValue == null;
        }
        public static bool IsNull(DateEdit control)
        {
            return control.Text.Length == 0 || control.EditValue == null || (DateTime)control.EditValue == DateTime.MinValue;
        }

        public static bool IsNull(ListBoxControl control)
        {
            return control.SelectedIndex < 0;
        }

        public static bool IsNull(GridView gview)
        {
            DataView dtSource = (DataView)gview.DataSource;
            if (dtSource != null && dtSource.Count > 0)
                return false;
            return true;
        }

        public static bool IsNull(RadioGroup control)
        {
            if (control.Properties.Items.Count == 0)
                return false;
            else
                for (int i = 0; i < control.Properties.Items.Count; i++)
                {
                    if (control.SelectedIndex >= 0)
                        return true;
                    else
                        return false;
                }
            return true;
        }

        #endregion IsNull

        #region Export

        /// <summary>
        /// Exports to excel.
        /// </summary>
        /// <param name="control">The control.</param>
        public static void ExportToExcel(GridControl control)
        {


            System.Windows.Forms.SaveFileDialog SFD = new SaveFileDialog();
            SFD.Filter = "Excel (*.xls)|*.xls";
            SFD.ShowDialog();
            if (SFD.FileName == string.Empty) return;
            control.ExportToExcelOld(SFD.FileName);
        }


        public static void TreeListExportToExcel(DevExpress.XtraTreeList.TreeList control)
        {
            System.Windows.Forms.SaveFileDialog SFD = new SaveFileDialog();
            SFD.Filter = "Excel (*.xls)|*.xls";
            SFD.ShowDialog();
            if (SFD.FileName == string.Empty) return;
            control.ExportToXls(SFD.FileName);
        }

        #endregion Export

        #region ResetControl

        /// <summary>
        /// Sets default value for controls on form
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="defaultValue">if set to <c>true</c> [default value].</param>
        public static void ResetControl(Control control, object defaultValue)
        {
            if (control is TextEdit || control is MemoEdit)
            {
                TextEdit textControl = control as TextEdit;
                textControl.EditValue = defaultValue;
            }
            else if (control is MemoEdit)
            {
                MemoEdit memoControl = control as MemoEdit;
                memoControl.EditValue = defaultValue;
            }

            //Call recursive this function to set default value for any child control
            foreach (Control ctrlChild in control.Controls)
                ResetControl(ctrlChild, defaultValue);
        }

        #endregion ResetControl

        #region SetReadOnly

        /// <summary>
        /// Sets readonly on form for any controls.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="readOnly">if set to <c>true</c> [read only].</param>
        public static void SetReadOnly(Control control, bool readOnly)
        {
            if (control is BaseEdit)
            {
                UI.SetReadOnly((BaseEdit)control, readOnly); //.Enabled = readOnly;
            }

            //if (control.GetType() == typeof(MemoEdit))
            //    control.Enabled = readOnly;

            //Call recursive this function to set readonly for any child control
            foreach (Control ctrlChild in control.Controls)
                SetReadOnly(ctrlChild, readOnly);
        }

        public void SetReadOnly(Control control)
        {
            SetReadOnly(control, true);
        }

        /// <summary>
        /// Sets the read only.
        /// </summary>
        /// <param name="readOnly">if set to <c>true</c> [read only].</param>
        public void SetReadOnly(bool readOnly)
        {
            SetReadOnly(this, readOnly);
        }

        #endregion SetReadOnly

        #region Fill Data

        #region FillDataToCombo

        /// <summary>
        /// Fills the data to ComboBoxEdit Control From Danh mục
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="maDanhMuc">Name of the group.</param>
        public static void FillDataToCombo(ComboBoxEdit control, string maDanhMuc, string dauMoiID)
        {
            string sql = "select DM.TuDienID, DM.TenGoi  " +
                          "From tblTuDien DM " +
                          "Where MaDanhMuc=@MaDanhMuc And DauMoiID=@DauMoiID Order By DM.TenGoi";
            List<SqlParameter> arrParameters = new List<SqlParameter>();
            arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, maDanhMuc));
            arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.NVarChar, ParameterDirection.Input, dauMoiID));

            DataTable temDT = SqlHelper.ExecuteDataTable(CommandType.Text, sql, arrParameters);

            for (int i = 0; i < temDT.Rows.Count; i++)
            {
                control.Properties.Items.Add(new ImageComboBoxItem(GetProperty(temDT.Rows[i], "TuDienID", string.Empty),
                    GetProperty(temDT.Rows[i], "TenGoi", string.Empty), i));
            }


            control.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
        }

        #endregion FillDataToCombo

        #region FillDataToComboBoxList

        /// <summary>
        /// Fills the data to ComboboxList Control.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="maDanhMuc">Name of the group.</param>
        public static void FillDataToComboBoxList(ListBoxControl control, string maDanhMuc)
        {
            //DM_ThamChieuAO thamChieuAO = new DM_ThamChieuAO();
            //thamChieuAO.ColBangCot = maDanhMuc;
            //DataTable dtGeneralRef = DM_ThamChieuBO.Instance.SelectList(thamChieuAO);

            //control.DataSource = dtGeneralRef;
            //control.DisplayMember = DM_THAMCHIEU.FIELD.COTGIATRI;
            //control.ValueMember = DM_THAMCHIEU.FIELD.COTID;
        }

        #endregion FillDataToComboBoxList

        public static void FillDataNhanVienToLookUp(LookUpEdit control)
        {
            string sql = "select NV.*  " +
                           "From tblNhanVien NV " +
                           "Order By HoTen ";

            DataTable temDT = SqlHelper.ExecuteDataTable(CommandType.Text, sql);

            control.Properties.Columns.Add(new LookUpColumnInfo("ID"));
            control.Properties.Columns["ID"].Caption = "ID";
            control.Properties.Columns["ID"].Width = 50;

            control.Properties.Columns.Add(new LookUpColumnInfo("HoTen"));
            control.Properties.Columns["HoTen"].Caption = "Nhân viên";
            control.Properties.Columns["HoTen"].Width = 200;
            control.Properties.Columns.Add(new LookUpColumnInfo("DiaChi"));
            control.Properties.Columns["DiaChi"].Caption = "Địa chỉ";
            control.Properties.Columns["DiaChi"].Width = 250;
            control.Properties.Columns.Add(new LookUpColumnInfo("DienThoai"));
            control.Properties.Columns["DienThoai"].Caption = "Điện thoại";
            control.Properties.Columns["DienThoai"].Width = 100;
            control.Properties.PopupWidth = 500;
            control.Properties.DisplayMember = "HoTen";
            control.Properties.ValueMember = "ID";


            DataRow dr = temDT.NewRow();
            dr["HoTen"] = "- Lựa chọn -";
            dr["ID"] = DBNull.Value;
            temDT.Rows.Add(dr);

            temDT.DefaultView.Sort = "HoTen";

            temDT.AcceptChanges();

            control.Properties.DataSource = temDT.DefaultView;

            control.Properties.TextEditStyle = TextEditStyles.Standard;
        }

        public static void FillDataDoiTuongToLookUp(LookUpEdit control)
        {
            string sql = "Select *  " +
                           "From tblDoiTuong " +
                           "Order By TenDT ";

            DataTable temDT = SqlHelper.ExecuteDataTable(CommandType.Text, sql);

            control.Properties.Columns.Add(new LookUpColumnInfo("ID"));
            control.Properties.Columns["ID"].Caption = "ID";
            control.Properties.Columns["ID"].Width = 30;

            control.Properties.Columns.Add(new LookUpColumnInfo("MaDT"));
            control.Properties.Columns["MaDT"].Caption = "Mã đối tượng";
            control.Properties.Columns["MaDT"].Width = 50;
            control.Properties.Columns.Add(new LookUpColumnInfo("TenDT"));
            control.Properties.Columns["TenDT"].Caption = "Tên đối tượng";
            control.Properties.Columns["TenDT"].Width = 200;
            control.Properties.Columns.Add(new LookUpColumnInfo("DiaChi"));
            control.Properties.Columns["DiaChi"].Caption = "Địa chỉ";
            control.Properties.Columns["DiaChi"].Width = 250;
            control.Properties.Columns.Add(new LookUpColumnInfo("DienThoai"));
            control.Properties.Columns["DienThoai"].Caption = "Điện thoại";
            control.Properties.Columns["DienThoai"].Width = 100;
            control.Properties.PopupWidth = 600;
            control.Properties.DisplayMember = "TenDT";
            control.Properties.ValueMember = "ID";


            DataRow dr = temDT.NewRow();
            dr["TenDT"] = "- Lựa chọn -";
            dr["ID"] = DBNull.Value;
            temDT.Rows.Add(dr);

            temDT.DefaultView.Sort = "TenDT";

            temDT.AcceptChanges();

            control.Properties.DataSource = temDT.DefaultView;

            control.Properties.TextEditStyle = TextEditStyles.Standard;
        }

        /// <summary>
        /// Tùy điều kiện truyền vào là khách hàng là 1, ngoài ra là nhà cung cấp
        /// </summary>
        /// <param name="control"></param>
        /// <param name="IsKhachHang"></param>
        public static void FillDataDoiTuongToLookUp(LookUpEdit control, bool IsKhachHang)
        {
            string sql = "Select *  " +
                           "From tblDoiTuong ";
            if (IsKhachHang)
                sql += "Where LaKhachHang=1 ";
            else
                sql += "Where LaNhaCungCap=1 ";
            sql += "Order By TenDT ";

            DataTable temDT = SqlHelper.ExecuteDataTable(CommandType.Text, sql);

            control.Properties.Columns.Add(new LookUpColumnInfo("ID"));
            control.Properties.Columns["ID"].Caption = "ID";
            control.Properties.Columns["ID"].Width = 30;

            control.Properties.Columns.Add(new LookUpColumnInfo("MaDT"));
            control.Properties.Columns["MaDT"].Caption = "Mã đối tượng";
            control.Properties.Columns["MaDT"].Width = 50;
            control.Properties.Columns.Add(new LookUpColumnInfo("TenDT"));
            control.Properties.Columns["TenDT"].Caption = "Tên đối tượng";
            control.Properties.Columns["TenDT"].Width = 200;
            control.Properties.Columns.Add(new LookUpColumnInfo("DiaChi"));
            control.Properties.Columns["DiaChi"].Caption = "Địa chỉ";
            control.Properties.Columns["DiaChi"].Width = 250;
            control.Properties.Columns.Add(new LookUpColumnInfo("DienThoai"));
            control.Properties.Columns["DienThoai"].Caption = "Điện thoại";
            control.Properties.Columns["DienThoai"].Width = 100;
            control.Properties.PopupWidth = 600;
            control.Properties.DisplayMember = "TenDT";
            control.Properties.ValueMember = "ID";


            DataRow dr = temDT.NewRow();
            dr["TenDT"] = "- Lựa chọn -";
            dr["ID"] = DBNull.Value;
            temDT.Rows.Add(dr);

            temDT.DefaultView.Sort = "TenDT";

            temDT.AcceptChanges();

            control.Properties.DataSource = temDT.DefaultView;

            control.Properties.TextEditStyle = TextEditStyles.Standard;
        }


        #region FillDataToLookUp

        public static void FillDataToLookUp(LookUpEdit control, string maDanhMuc, string dauMoiID)
        {
            FillDataToLookUp(control, maDanhMuc, dauMoiID, false);
        }

        /// <summary>
        /// Fills the data to LookUpEdit Control.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="maDanhMuc">Name of the group.</param>
        public static void FillDataToLookUp(LookUpEdit control, string maDanhMuc, string dauMoiID, bool flagNotNull)
        {
            control.Properties.Columns.Clear();

            string sql = "select DM.TuDienID, DM.TenGoi  " +
                           "From tblTuDien DM " +
                           "Where MaDanhMuc=@MaDanhMuc And DauMoiID=@DauMoiID Order By DM.TenGoi";
            List<SqlParameter> arrParameters = new List<SqlParameter>();
            arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, maDanhMuc));
            arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.NVarChar, ParameterDirection.Input, dauMoiID));

            DataTable temDT = SqlHelper.ExecuteDataTable(CommandType.Text, sql, arrParameters);
            control.Properties.Columns.Add(new LookUpColumnInfo("TenGoi"));
            control.Properties.Columns["TenGoi"].Caption = "Tên gọi";

            control.Properties.DisplayMember = "TenGoi";
            control.Properties.ValueMember = "TuDienID";

            if (!flagNotNull)
            {
                DataRow dr = temDT.NewRow();
                dr["TenGoi"] = "- - -";
                dr["TuDienID"] = DBNull.Value;
                temDT.Rows.Add(dr);
            }
            temDT.DefaultView.Sort = "TenGoi";

            temDT.AcceptChanges();

            control.Properties.DataSource = temDT.DefaultView;

            control.Properties.TextEditStyle = TextEditStyles.Standard;

            if (temDT.Rows.Count < 10)
                control.Properties.DropDownRows = temDT.Rows.Count;
            else
                control.Properties.DropDownRows = 10;
        }

        public static void FillDataToLookUp(DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit control, string maDanhMuc, string DauMoiID, bool flagNotNull)
        {
            control.Properties.Columns.Clear();

            string sql = "select DM.TuDienID, DM.TenGoi  " +
                           "From tblTuDien DM " +
                           "Where MaDanhMuc=@MaDanhMuc And DauMoiID=@DauMoiID And Deleted=0 Order By DM.TenGoi";
            List<SqlParameter> arrParameters = new List<SqlParameter>();
            arrParameters.Add(SqlHelper.CreateParameterObject("@MaDanhMuc", SqlDbType.NVarChar, ParameterDirection.Input, maDanhMuc));
            arrParameters.Add(SqlHelper.CreateParameterObject("@DauMoiID", SqlDbType.Int, ParameterDirection.Input, DauMoiID));

            DataTable temDT = SqlHelper.ExecuteDataTable(CommandType.Text, sql, arrParameters);
            control.Properties.Columns.Add(new LookUpColumnInfo("TenGoi"));
            control.Properties.Columns["TenGoi"].Caption = "Tên gọi";

            control.Properties.DisplayMember = "TenGoi";
            control.Properties.ValueMember = "TuDienID";

            if (!flagNotNull)
            {
                DataRow dr = temDT.NewRow();
                dr["TenGoi"] = "- Lựa chọn -";
                dr["TuDienID"] = DBNull.Value;
                temDT.Rows.Add(dr);
            }
            temDT.DefaultView.Sort = "TenGoi";

            temDT.AcceptChanges();

            control.Properties.DataSource = temDT.DefaultView;

            control.Properties.TextEditStyle = TextEditStyles.Standard;
        }


        public static void FillDataToGeneralRefGridCombo(DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit control, string maDanhMuc)
        {
            //control.Columns.Clear();
            //DM_ThamChieuAO thamChieuAO = new DM_ThamChieuAO();
            //thamChieuAO.ColBangCot = maDanhMuc;
            //DataTable dtGeneralRef = DM_ThamChieuBO.Instance.SelectList(thamChieuAO);
            //control.Columns.Add(new LookUpColumnInfo(DM_THAMCHIEU.FIELD.COTGIATRI));

            //thamChieuAO.ColBangCot = DM_THAMCHIEU.FIELD.BANGCOT;
            //thamChieuAO.ColCotID = maDanhMuc;

            //DM_ThamChieuBO.Instance.Get(thamChieuAO);
            //if (thamChieuAO.ColCotGiaTri.Length > 0)
            //    control.Columns[DM_THAMCHIEU.FIELD.COTGIATRI].Caption = thamChieuAO.ColCotGiaTri;
            //else
            //    control.Columns[DM_THAMCHIEU.FIELD.COTGIATRI].Caption = maDanhMuc;

            //control.DisplayMember = DM_THAMCHIEU.FIELD.COTGIATRI;
            //control.ValueMember = DM_THAMCHIEU.FIELD.COTID;

            //DataRow dr = dtGeneralRef.NewRow();
            //dr[DM_THAMCHIEU.FIELD.COTGIATRI] = "- Lựa chọn -";
            //dr[DM_THAMCHIEU.FIELD.COTID] = DBNull.Value;


            //dtGeneralRef.Rows.Add(dr);
            //dtGeneralRef.DefaultView.Sort = DM_THAMCHIEU.FIELD.COTGIATRI;
            //dtGeneralRef.AcceptChanges();

            //control.DataSource = dtGeneralRef.DefaultView;
            //control.TextEditStyle = TextEditStyles.DisableTextEditor;
        }

        public static void FillDataToGeneralRefComboUnKownItem(LookUpEdit control, string maDanhMuc)
        {
            //control.Properties.Columns.Clear();
            //DM_ThamChieuAO thamChieuAO = new DM_ThamChieuAO();
            //thamChieuAO.ColBangCot = maDanhMuc;
            //DataTable dtGeneralRef = DM_ThamChieuBO.Instance.SelectList(thamChieuAO);

            //control.Properties.Columns.Add(new LookUpColumnInfo(DM_THAMCHIEU.FIELD.COTGIATRI));

            //thamChieuAO.ColCotID = maDanhMuc;
            //thamChieuAO.ColBangCot = DM_THAMCHIEU.FIELD.BANGCOT;

            //DM_ThamChieuBO.Instance.Get(thamChieuAO);
            //if (thamChieuAO.ColCotGiaTri.Length > 0)
            //    control.Properties.Columns[DM_THAMCHIEU.FIELD.COTGIATRI].Caption = thamChieuAO.ColCotGiaTri;
            //else
            //    control.Properties.Columns[DM_THAMCHIEU.FIELD.COTGIATRI].Caption = maDanhMuc;

            //control.Properties.DisplayMember = DM_THAMCHIEU.FIELD.COTGIATRI;
            //control.Properties.ValueMember = DM_THAMCHIEU.FIELD.COTID;

            ////DataRow dr = dtGeneralRef.NewRow();
            ////dr[DM_THAMCHIEU.FIELD.COTGIATRI] = "- Không xác định -";
            ////dr[DM_THAMCHIEU.FIELD.COTID] = THAMCHIEU.QuocGia.KHONGXACDINH;


            ////dtGeneralRef.Rows.Add(dr);
            //dtGeneralRef.DefaultView.Sort = DM_THAMCHIEU.FIELD.COTGIATRI;
            //dtGeneralRef.AcceptChanges();

            //control.Properties.DataSource = dtGeneralRef.DefaultView;
            //control.Properties.TextEditStyle = TextEditStyles.Standard;
        }

        #endregion FillDataToLookUp

        #region FillDataToCheckBoxList



        #endregion FillDataToCheckBoxList

        #region FillDataToRadioGroup



        #endregion FillDataToRadioGroup

        #endregion Fill Data

        #region ComboBox

        // Rename the old function later
        public static void FillDataToGeneralRefCombo(LookUpEdit control, string maDanhMuc, string dauMoiID)
        {
            FillDataToLookUp(control, maDanhMuc, dauMoiID);
        }

        public static void FillDataToGeneralRefCombo(LookUpEdit control, string maDanhMuc, string dauMoiID, bool flagNotNull)
        {
            FillDataToLookUp(control, maDanhMuc, dauMoiID, flagNotNull);
        }

        public static void FillDataToOrderCombo(LookUpEdit control)
        {

        }

        public static void AddNullItemToCombo(LookUpEdit control)
        {
            try
            {
                #region Add null select row
                DataTable dtSource = (DataTable)control.Properties.DataSource;
                DataRow dr = dtSource.NewRow();

                dr[control.Properties.DisplayMember] = "- Lựa chọn -";
                dr[control.Properties.ValueMember] = DBNull.Value;
                dtSource.Rows.Add(dr);
                dtSource.DefaultView.Sort = control.Properties.DisplayMember;
                dtSource.AcceptChanges();

                #endregion Add null select row
            }
            catch { }
        }

        public static void AddNullItemToCombo(GridLookUpEdit control)
        {
            try
            {
                #region Add null select row
                DataTable dtSource = (DataTable)control.Properties.DataSource;
                DataRow dr = dtSource.NewRow();

                dr[control.Properties.DisplayMember] = "- Lựa chọn -";
                dr[control.Properties.ValueMember] = DBNull.Value;
                dtSource.Rows.Add(dr);
                dtSource.DefaultView.Sort = control.Properties.DisplayMember;
                dtSource.AcceptChanges();

                #endregion Add null select row
            }
            catch { }
        }

        public static void AddNullItemToCombo(DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit control)
        {
            try
            {
                #region Add null select row
                DataTable dtSource = (DataTable)control.Properties.DataSource;
                DataRow dr = dtSource.NewRow();

                dr[control.DisplayMember] = "- Lựa chọn -";
                dr[control.ValueMember] = DBNull.Value;
                dtSource.Rows.Add(dr);
                dtSource.DefaultView.Sort = control.DisplayMember;
                dtSource.AcceptChanges();

                #endregion Add null select row
            }
            catch { }
        }

        public static void AddNullItemToCombo(ComboBoxEdit control)
        {
            ShowWarningMessage("View: public static void AddNullItemToCombo(ComboBoxEdit control)");
        }

        public static void AddUnKnownItemToCombo(LookUpEdit control)
        {
            //#region Add unkown select row
            //DataTable dtSource = (DataTable)control.Properties.DataSource;
            //DataRow dr = dtSource.NewRow();

            //dr[control.Properties.DisplayMember] = "- Không xác định -";
            //dr[control.Properties.ValueMember] = THAMCHIEU.QuocGia.KHONGXACDINH;
            //dtSource.Rows.Add(dr);
            //dtSource.DefaultView.Sort = control.Properties.DisplayMember;
            //dtSource.AcceptChanges();

            //#endregion Add null select row
        }

        #endregion ComboBox

        #region MessageBox

        public static void ShowInfoMessage(object info)
        {
            if (info != null)
                XtraMessageBox.Show(info.ToString(), "TCCT_CTC_CSDLDangVienV1", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        public static void ShowErrorMessage(object erro)
        {
            XtraMessageBox.Show(erro.ToString(), "TCCT_CTC_CSDLDangVienV1", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        public static void ShowWarningMessage(object warning)
        {
            XtraMessageBox.Show(warning.ToString(), "TCCT_CTC_CSDLDangVienV1", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        public static DialogResult ShowQuestionMessage(string question)
        {
            return XtraMessageBox.Show(question + "\nChấp nhận(Yes) \\ Bỏ qua(No)", "TCCT_CTC_CSDLDangVienV1", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        }

        public static DialogResult ShowConfirmMessage(string question)
        {
            return XtraMessageBox.Show(question + "\nChấp nhận(Yes) \\ Bỏ qua(No)", "TCCT_CTC_CSDLDangVienV1", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        }

        public static DialogResult ShowConfirmMessageToSave(string question)
        {
            return XtraMessageBox.Show(question + "\nChấp nhận(Yes) \\ Bỏ qua(No) \\ Hủy bỏ(Cancel)", "TCCT_CTC_CSDLDangVienV1", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
        }


        public static string GetMessageContent(string message, object param)
        {
            if (param == null) return message;

            return string.Format(message, param);
        }

        public static string GetMessageContent(string message)
        {
            return GetMessageContent(message, null);
        }

        #endregion MessageBox

        #region RadioGroup

        public static void FillReneralRefDataToRadio(RadioGroup control, string maDanhMuc)
        {
            //DM_ThamChieuAO danhMucThamChieuAO = new DM_ThamChieuAO();
            //danhMucThamChieuAO.ColBangCot = maDanhMuc;
            //DataTable danhMucThamChieuList = DM_ThamChieuBO.Instance.SelectDataForGrid(danhMucThamChieuAO);

            //control.EditValue = null;
            //if (danhMucThamChieuList.Rows.Count > 0)
            //{
            //    for (int i = 0; i < danhMucThamChieuList.Rows.Count; i++)
            //    {
            //        control.Properties.Items.Add(
            //            new DevExpress.XtraEditors.Controls.RadioGroupItem(
            //                danhMucThamChieuList.Rows[i][DM_THAMCHIEU.FIELD.COTID].ToString(),
            //                danhMucThamChieuList.Rows[i][DM_THAMCHIEU.FIELD.COTGIATRI].ToString()));
            //        if (control.EditValue == null)
            //            control.EditValue = danhMucThamChieuList.Rows[i][DM_THAMCHIEU.FIELD.COTID].ToString();
            //    }
            //}
        }

        #endregion RadioGroup



        #endregion Static Methods

        #region Protected Methods

        #region Dispose

        public delegate void ProcessReturnedObject(object returnObject);
        public event ProcessReturnedObject ReturnObjectEvent;
        public void OnProcessReturnedObject(object returnObject)
        {
            if (ReturnObjectEvent != null)
                ReturnObjectEvent(returnObject);
        }

        protected override void Dispose(bool disposing)
        {
            OnProcessReturnedObject(null);
            base.Dispose(disposing);
        }

        #endregion Dispose



        #endregion Protected Methods

        #region Public Methods


        #region LoadComBo

        //TODO


        #endregion LoadComBo



        #endregion Public Methods

        #region ResetTextValues

        /// <summary>
        /// Sodv: Resets the text values in XtraGroup contener
        /// Dành cho các đối tượng được thiết kế nằm trên XtraGroup
        /// </summary>
        /// <param name="contener">The contener.</param>
        public void ResetValues(DevExpress.XtraEditors.GroupControl contener)
        {
            DevExpress.XtraEditors.TextEdit textBox = new DevExpress.XtraEditors.TextEdit();
            DevExpress.XtraEditors.MemoEdit memoEdit = new MemoEdit();
            DevExpress.XtraEditors.LabelControl labelControl = new LabelControl();
            LookUpEdit lookUpEdit = new LookUpEdit();
            DateEdit dateEdit = new DateEdit();
            GridLookUpEdit gridLookUpEdit = new GridLookUpEdit();
            CheckEdit checkEdit = new CheckEdit();
            ButtonEdit buttonEdit = new ButtonEdit();

            foreach (Control ctr in contener.Controls)
            {
                if (ctr.GetType() != labelControl.GetType())
                {
                    if (ctr.GetType() == textBox.GetType() || ctr.GetType() == memoEdit.GetType())
                    {
                        ctr.Text = string.Empty;
                    }
                    else if (ctr.GetType() == lookUpEdit.GetType())
                    {
                        ((LookUpEdit)ctr).ItemIndex = -1;
                        ((LookUpEdit)ctr).EditValue = null;
                    }
                    else if (ctr.GetType() == dateEdit.GetType())
                    {
                        ((DateEdit)ctr).EditValue = null;
                    }
                    else if (ctr.GetType() == checkEdit.GetType())
                    {
                        ((CheckEdit)ctr).Checked = false;
                    }
                    else if (ctr.GetType() == gridLookUpEdit.GetType())
                    {
                        ((GridLookUpEdit)ctr).EditValue = null;
                    }
                    else if (ctr.GetType() == buttonEdit.GetType())
                    {
                        ((ButtonEdit)ctr).EditValue = string.Empty;
                        ((ButtonEdit)ctr).Text = string.Empty;
                    }
                    ResetValues(ctr);
                }
            }
        }
        public void ResetValues(Control contener)
        {
            //TODO: định nghĩa thêm kiểu điều khiển cần reset text vào đây và cho thêm điều kiện hoặc vào biểu thức so sánh kiểu:
            DevExpress.XtraEditors.TextEdit textBox = new DevExpress.XtraEditors.TextEdit();
            DevExpress.XtraEditors.MemoEdit memoEdit = new MemoEdit();
            DevExpress.XtraEditors.LabelControl labelControl = new LabelControl();
            LookUpEdit lookUpEdit = new LookUpEdit();
            DateEdit dateEdit = new DateEdit();
            GridLookUpEdit gridLookUpEdit = new GridLookUpEdit();
            CheckEdit checkEdit = new CheckEdit();
            ButtonEdit buttonEdit = new ButtonEdit();

            foreach (Control ctr in contener.Controls)
            {
                if (ctr.GetType() != labelControl.GetType())
                {
                    if (ctr.GetType() == textBox.GetType() || ctr.GetType() == memoEdit.GetType())
                    {
                        ctr.Text = string.Empty;
                    }
                    else if (ctr.GetType() == lookUpEdit.GetType())
                    {
                        ((LookUpEdit)ctr).ItemIndex = -1;
                        ((LookUpEdit)ctr).EditValue = null;
                    }
                    else if (ctr.GetType() == dateEdit.GetType())
                    {
                        ((DateEdit)ctr).EditValue = null;
                    }
                    else if (ctr.GetType() == checkEdit.GetType())
                    {
                        ((CheckEdit)ctr).Checked = false;
                    }
                    else if (ctr.GetType() == gridLookUpEdit.GetType())
                    {
                        ((GridLookUpEdit)ctr).EditValue = null;
                    }
                    else if (ctr.GetType() == buttonEdit.GetType())
                    {
                        ((ButtonEdit)ctr).EditValue = string.Empty;
                        ((ButtonEdit)ctr).Text = string.Empty;
                    }
                    ResetValues(ctr);
                }
            }
        }

        /// <summary>
        /// Sodv: Resets the text values in Window form.
        /// Dành cho các đối tượng được thiết kế nằm trên nền form
        /// </summary>
        public void ResetTextValues()
        {
            DevExpress.XtraEditors.TextEdit textBox = new DevExpress.XtraEditors.TextEdit();
            //TODO: định nghĩa thêm kiểu điều khiển cần reset text vào đây và cho thêm điều kiện hoặc vào biểu thức so sánh kiểu:
            //DevExpress.XtraEditors.MemoEdit memoEdit = new MemoEdit();

            foreach (Control ctr in this.Controls)
            {
                if (ctr.GetType() == textBox.GetType())//|| ctr.GetType() == memoEdit.GetType()
                {
                    ctr.Text = string.Empty;
                }
            }
        }

        #endregion ResetTextValues




        #region Validation

        #region ValidateRequiredFields

        /// <summary>
        /// Validation Required for TextEdit
        /// </summary>
        /// <param name="control">TextEdit Control</param>
        /// <param name="captionText">Label's caption of Control</param>
        /// <returns></returns>
        protected bool ValidateRequiredField(ref TextEdit control, string captionText)
        {
            try
            {
                if (IsNull(control))
                {
                    if (ValidationRequire == null || _validationRequire.Count == 0)
                        control.Focus();
                    this.AppendValidationRequireMessage(captionText);
                    return false;
                }
                else
                {
                    if ((ValidationRequire != null && _validationRequire.Count > 0) ||
                        (ValidationMessage != null && _validationMessage.Count > 0))
                        return false;
                    else
                        return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// Validation Required for MemoEdit
        /// </summary>
        /// <param name="control">MemoEdit Control</param>
        /// <param name="captionText">Label's caption of Control</param>
        /// <returns></returns>
        protected bool ValidateRequiredField(ref MemoEdit control, string captionText)
        {
            try
            {
                if (IsNull(control))
                {
                    if (ValidationRequire == null || _validationRequire.Count == 0)
                        control.Focus();
                    this.AppendValidationRequireMessage(captionText);
                    return false;
                }
                else
                {
                    if ((ValidationRequire != null && _validationRequire.Count > 0) ||
                        (ValidationMessage != null && _validationMessage.Count > 0))
                        return false;
                    else
                        return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// Validation Required for LookUpEdit
        /// </summary>
        /// <param name="control">LookUpEdit Control</param>
        /// <param name="captionText">Label's caption of Control</param>
        /// <returns></returns>
        protected bool ValidateRequiredField(ref LookUpEdit control, string captionText)
        {
            try
            {
                if (IsNull(control))
                {
                    if (ValidationRequire == null || ValidationRequire.Count == 0)
                        control.Focus();
                    this.AppendValidationRequireMessage(captionText);
                    return false;
                }
                else
                {
                    if ((ValidationRequire != null && _validationRequire.Count > 0) ||
                        (ValidationMessage != null && _validationMessage.Count > 0))
                        return false;
                    else
                        return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }
        protected bool ValidateRequiredFieldByText(ref LookUpEdit control, string captionText)
        {
            try
            {
                if (control.Text.Trim().Length == 0)
                {
                    if (ValidationRequire == null || ValidationRequire.Count == 0)
                        control.Focus();
                    this.AppendValidationRequireMessage(captionText);
                    return false;
                }
                else
                {
                    if ((ValidationRequire != null && _validationRequire.Count > 0) ||
                        (ValidationMessage != null && _validationMessage.Count > 0))
                        return false;
                    else
                        return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// Validation Required for GridLookUpEdit
        /// </summary>
        /// <param name="control">GridLookUpEdit Control</param>
        /// <param name="captionText">Label's caption of Control</param>
        /// <returns></returns>
        protected bool ValidateRequiredField(ref GridLookUpEdit control, string captionText)
        {
            try
            {
                if (IsNull(control))
                {
                    if (ValidationRequire == null || ValidationRequire.Count == 0)
                        control.Focus();
                    this.AppendValidationRequireMessage(captionText);
                    return false;
                }
                else
                {
                    if ((ValidationRequire != null && _validationRequire.Count > 0) ||
                        (ValidationMessage != null && _validationMessage.Count > 0))
                        return false;
                    else
                        return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// Validation Required for ButtonEdit
        /// </summary>
        /// <param name="control">ButtonEdit Control</param>
        /// <param name="captionText">Label's caption of Control</param>
        /// <returns></returns>
        protected bool ValidateRequiredField(ref ButtonEdit control, string captionText)
        {
            try
            {
                if (IsNull(control))
                {
                    if (ValidationRequire == null || ValidationRequire.Count == 0)
                        control.Focus();
                    this.AppendValidationRequireMessage(captionText);
                    return false;
                }
                else
                {
                    if ((ValidationRequire != null && _validationRequire.Count > 0) ||
                        (ValidationMessage != null && _validationMessage.Count > 0))
                        return false;
                    else
                        return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// Validation Required for DateEdit
        /// </summary>
        /// <param name="control">DateEdit Control</param>
        /// <param name="captionText">Label's caption of Control</param>
        /// <returns></returns>
        protected bool ValidateRequiredField(ref DateEdit control, string captionText)
        {
            try
            {
                if (IsNull(control))
                {
                    if (ValidationRequire == null || ValidationRequire.Count == 0)
                        control.Focus();
                    this.AppendValidationRequireMessage(captionText);
                    return false;
                }
                else
                {
                    if ((ValidationRequire != null && _validationRequire.Count > 0) ||
                        (ValidationMessage != null && _validationMessage.Count > 0))
                        return false;
                    else
                        return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// Validation Required for ListBoxControl
        /// </summary>
        /// <param name="control">ListBoxControl Control</param>
        /// <param name="captionText">Label's caption of Control</param>
        /// <returns></returns>
        protected bool ValidateRequiredField(ref ListBoxControl control, string captionText)
        {
            try
            {
                if (IsNull(control))
                {
                    if (ValidationRequire == null || ValidationRequire.Count == 0)
                        control.Focus();
                    this.AppendValidationRequireMessage(captionText);
                    return false;
                }
                else
                {
                    if ((ValidationRequire != null && _validationRequire.Count > 0) ||
                        (ValidationMessage != null && _validationMessage.Count > 0))
                        return false;
                    else
                        return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// Validation Required for GridView
        /// </summary>
        /// <param name="control">GridView Control</param>
        /// <param name="captionText">Label's caption of Control</param>
        /// <returns></returns>
        protected bool ValidateRequiredField(ref GridView control, string captionText)
        {
            try
            {
                if (IsNull(control))
                {
                    if (ValidationRequire == null || ValidationRequire.Count == 0)
                        control.Focus();
                    this.AppendValidationRequireMessage(captionText);
                    return false;
                }
                else
                {
                    if ((ValidationRequire != null && _validationRequire.Count > 0) ||
                        (ValidationMessage != null && _validationMessage.Count > 0))
                        return false;
                    else
                        return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }

        protected bool ValidateRequiredField(ref RadioGroup control, string captionText)
        {
            try
            {
                if (IsNull(control))
                {
                    if (ValidationRequire == null || ValidationRequire.Count == 0)
                        control.Focus();
                    this.AppendValidationRequireMessage(captionText);
                    return false;
                }
                else
                {
                    if ((ValidationRequire != null && _validationRequire.Count > 0) ||
                        (ValidationMessage != null && _validationMessage.Count > 0))
                        return false;
                    else
                        return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }

        #endregion ValidateRequiredFields

        /// <summary>
        /// Appends the Required Fields for Validation Message
        /// </summary>
        /// <param name="message">Caption</param>
        protected void AppendValidationRequireMessage(string caption)
        {
            this.ValidationRequire.Add(caption);
        }

        /// <summary>
        /// Appends the validation message.
        /// </summary>
        /// <param name="message">The message.</param>
        protected void AppendValidationMessage(string message)
        {
            this.ValidationMessage.Add(message);
        }

        /// <summary>
        /// Shows the validation message.
        /// </summary>
        protected void ShowValidationMessage()
        {
            if (this._validationMessage == null)
                this._validationMessage = new ArrayList();
            if (this._validationRequire == null)
                this._validationRequire = new ArrayList();
            if (this._validationRequire.Count == 0 && this._validationMessage.Count == 0)
                return;

            string validationMessage = string.Empty;

            if (_validationRequire.Count > 0)
            {
                for (int i = 0; i < _validationRequire.Count; i++)
                {
                    string curItem = (string)_validationRequire[i];
                    if (i == 0)
                        validationMessage += "sodv" + "\n" + curItem;
                    else
                        validationMessage += ", " + curItem;
                }
            }
            validationMessage += "\n";


            if (_validationMessage.Count > 0)
            {
                foreach (string message in _validationMessage)
                {
                    validationMessage += message + "\n";
                }
            }

            ShowWarningMessage(validationMessage);
        }

        #endregion Validation

        #region Exception Handler

        #region ProcessException

        ///// <summary>
        ///// Processes the exception.
        ///// </summary>
        ///// <param name="se">The sql exception</param>
        //public static void ProcessException(SQLException se)
        //{
        //    ShowErrorMessage(se.DetailMessage);
        //}

        /// <summary>
        /// Processes the exception.
        /// </summary>
        /// <param name="ex">The general exception</param>
        public static void ProcessException(Exception ex)
        {
            ShowErrorMessage(ex);
        }

        #endregion ProcessException


        #endregion
    }
}